'''
config表
'''
from mongoengine import Document, BooleanField, IntegerField, StringField, ListField, EmbeddedDocumentField

class Config(Document):
    # 异步生成
    async_work = BooleanField(default=False)
    seed_count = IntegerField(default=1)

    meta = {
        'collection': 'config',
        'db_alias': 'painter'
    }

    @classmethod
    def get_async_word(cls):
        config = cls.objects.first()
        return config.async_work if config else False

    @classmethod
    def get_seed_count(cls):
        config = cls.objects.first()
        return config.seed_count if config else 1

    @classmethod
    def get_config_value(cls, field_name, default=None):
        """通用配置获取方法"""
        config = cls.objects.first()
        if config and hasattr(config, field_name):
            return getattr(config, field_name)
        return default